package com.feriki.msync.meta;

import io.milvus.grpc.DataType;
import io.milvus.param.collection.FieldType;
import lombok.Data;

import java.util.Map;

/**
 * @author luozhida
 * @create 2024-07-09
 */
@Data
public class FieldTypeMeta {
    private String name;
    private boolean primaryKey;
    private String description;
    private int dataType;
    private Map<String,String> typeParams;
    private boolean autoID;
    private boolean partitionKey;
    private boolean isDynamic;
    private int elementType;
    private boolean vectorKey;


    public FieldType toMilvusFieldType(){
        return FieldType.newBuilder().withName(name)
                .withPrimaryKey(primaryKey)
                .withDescription(description)
                .withDataType(DataType.forNumber(dataType))
                .withTypeParams(typeParams)
                .withAutoID(autoID)
                .withPartitionKey(partitionKey)
                .withIsDynamic(isDynamic)
                .withElementType(DataType.forNumber(elementType))
                .build();
    }

    public void transferFrom(FieldType fieldType){
        this.name = fieldType.getName();
        this.primaryKey = fieldType.isPrimaryKey();
        this.description = fieldType.getDescription();
        this.dataType = fieldType.getDataType().getNumber();
        this.typeParams = fieldType.getTypeParams();
        this.autoID = fieldType.isAutoID();
        this.partitionKey = fieldType.isPartitionKey();
        this.isDynamic = fieldType.isDynamic();
        this.elementType = fieldType.getElementType().getNumber();
    }


}
